<?php

$dsthi=$_GET['ds_thi'];//
$sql_tt_dsthi=" SELECT  khungthoigian,ten_mh,ten_nganh,ngaythi 
                FROM    tbl_dsthi,dm_cahoc,tbl_mon_ctdt,dm_monhoc,tbl_ctdt,dm_nganh
                WHERE   tbl_dsthi.madm_ca=dm_cahoc.madm_ca
                AND     tbl_dsthi.ma_mon_ctdt=tbl_mon_ctdt.ma_mon_ctdt
                AND     tbl_ctdt.ma_ctdt=tbl_mon_ctdt.ma_ctdt
                AND     tbl_mon_ctdt.ma_monhoc=dm_monhoc.madm_mh
                AND     tbl_ctdt.madm_nganh=dm_nganh.madm_nganh
                AND     ma_dsthi='$dsthi'";
                
$ex_tt_dslich=mysql_query($sql_tt_dsthi);
$kq=mysql_fetch_array($ex_tt_dslich);                

$smarty->assign('kq_tt_ds',$kq);
$smarty->assign('dsthi',$dsthi);
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4
if(isset($_POST['Luu'])){
    $somax=$_POST['somax'];
    $nguoinhap=$_SESSION['ma_cb'];
    $thoigian=date('H:m:i d/m/Y');
    for($i=1;$i<$somax;$i++){
        $ma_diemthi= $_POST['ma_diemthi'.$i];
        $diemthi= $_POST['diem'.$i];
        $sql_update="UPDATE tbl_diemthi SET diemthi='$diemthi',ma_cb='$nguoinhap',thoigiannhap='$thoigian',
                                            ma_tt_diemthi='danhap'
                                            WHERE ma_diemthi='$ma_diemthi'";
        mysql_query($sql_update);                                                
    }
    //Cập nhật thông tin danh sách thi với trạng thái là đã duyệt
    $sql_update_dsthi="UPDATE tbl_dsthi SET trangthai_dsthi='danhap' WHERE ma_dsthi='$dsthi'";
    mysql_query($sql_update_dsthi);
}


//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4
$sql_sv_lopmon="    SELECT  tbl_dangkymon.*,hoten_sv,ngaysinh_sv,ten_lop,ma_diemthi,lanthi,diemthi
                    FROM    tbl_dangkymon,tbl_sinhvien,tbl_nhaphoc,tbl_sv_lop,tbl_lop,tbl_diemthi
                    WHERE   tbl_dangkymon.ma_sv=tbl_sinhvien.ma_sv
                    AND     tbl_sinhvien.ma_sv=tbl_nhaphoc.ma_sv
                    AND     tbl_nhaphoc.ma_nhaphoc=tbl_sv_lop.ma_nhaphoc
                    AND     tbl_sv_lop.ma_lop=tbl_lop.ma_lop
                    AND     tbl_diemthi.ma_dkm=tbl_dangkymon.ma_dkm
                    AND     ngayra_nhaphoc = ''
                    AND     ma_dsthi='$dsthi'
                    ORDER BY ten_sv,hoten_sv ASC";
$ds_sv=null;
$ds_dkm=null;
$ex_sv_lopmon=mysql_query($sql_sv_lopmon);
while($row=mysql_fetch_array($ex_sv_lopmon)){
    $ds_sv[]=$row;
    $ds_dkm.="'".$row['ma_dkm']."',";
}

$smarty->assign('dssv',$ds_sv);
$ds_dkm=rtrim($ds_dkm,",");
                           
$ex_check_cc=mysql_query("  SELECT  tbl_ketquaquatrinh.ma_dkm,diem_kqqt 
                            FROM    tbl_dangkymon,tbl_ketquaquatrinh,tbl_monctdt_tieuchi
                            WHERE   tbl_dangkymon.ma_dkm=tbl_ketquaquatrinh.ma_dkm
                            AND     tbl_monctdt_tieuchi.ma_monctdt_tieuchi=tbl_ketquaquatrinh.ma_monctdt_tieuchi
                            AND     madm_tieuchimonhoc='cc'
                            AND     tbl_dangkymon.ma_dkm IN ($ds_dkm)");


$arr_kqqt_cc=array();
$arr_kqqt_cc=null;
$arr_kqqt_dk=array();
$arr_kqqt_dk=null;


if(mysql_num_rows($ex_check_cc)>0){
    while($row=mysql_fetch_array($ex_check_cc)){
        $key=$row['ma_dkm'];
        $arr_kqqt_cc[$key]=$row['diem_kqqt'];    
    }
    
        $ex_check_dk=mysql_query(" SELECT  tbl_ketquaquatrinh.ma_dkm,diem_kqqt 
                                    FROM    tbl_dangkymon,tbl_ketquaquatrinh,tbl_monctdt_tieuchi
                                    WHERE   tbl_dangkymon.ma_dkm=tbl_ketquaquatrinh.ma_dkm
                                    AND     tbl_monctdt_tieuchi.ma_monctdt_tieuchi=tbl_ketquaquatrinh.ma_monctdt_tieuchi
                                    AND     madm_tieuchimonhoc='dk'
                                    AND     tbl_dangkymon.ma_dkm IN ($ds_dkm)");
        
        if(mysql_num_rows($ex_check_dk)>0){
            while($row=mysql_fetch_array($ex_check_dk)){
                $key=$row['ma_dkm'];
                $arr_kqqt_dk[$key]=$row['diem_kqqt'];    
            }
        }
}

$smarty->assign('arr_kqqt_cc',$arr_kqqt_cc);
$smarty->assign('arr_kqqt_dk',$arr_kqqt_dk);


//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$smarty->display('diem/add_diemthi.tpl');   
?>












